<?php

/**
 * This is the model class for table "tbl_reader".
 *
 * The followings are the available columns in table 'tbl_reader':
 * @property integer $readerID
 * @property string $name
 * @property string $sex
 * @property string $IDType
 * @property string $IDNum
 * @property string $phoneNum
 * @property string $address
 * @property string $balance
 * @property string $photoPath
 *
 * The followings are the available model relations:
 * @property Bbrecords[] $bbrecords
 * @property Monyrec[] $monyrecs
 */
class Reader extends CActiveRecord
{
	/**
	 * 定义读者管理用到的常量
	 */
	const MENU_NAME='读者管理';
	const MENU_CREAT='新增读者';
	const MENU_UPDATE='更新读者信息';
	const MENU_DEL='删除读者信息';
	const MENU_ADMIN='管理读者信息';
	const MENU_BROWSE='浏览读者信息';
	
	const ADD_MONEY='充值';
	const DEDU_MONEY='扣钱';
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Reader the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_reader';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, phoneNum', 'length', 'max'=>15),
			array('sex', 'length', 'max'=>1),
			array('IDType', 'length', 'max'=>11),
			array('IDNum', 'length', 'max'=>21),
			array('address', 'length', 'max'=>51),
			array('balance', 'length', 'max'=>8),
			array('photoPath', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('readerID, name, sex, IDType, IDNum, phoneNum, address, balance, photoPath', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bbrecords' => array(self::HAS_MANY, 'Bbrecords', 'readerID'),
			'monyrecs' => array(self::HAS_MANY, 'Monyrec', 'readerID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'readerID' => '读者编号',
			'name' => '姓名',
			'sex' => '性别',
			'IDType' => '证件类型',
			'IDNum' => '证件编号',
			'phoneNum' => '联系电话',
			'address' => '地址',
			'balance' => '余额',
			'photoPath' => '照片路径',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('readerID',$this->readerID);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('sex',$this->sex,true);
		$criteria->compare('IDType',$this->IDType,true);
		$criteria->compare('IDNum',$this->IDNum,true);
		$criteria->compare('phoneNum',$this->phoneNum,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('balance',$this->balance,true);
		$criteria->compare('photoPath',$this->photoPath,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}